home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
- Begin VB.Form frmTest
- Caption = "SG FileSys - Enumerating Files Sample"
- ClientHeight = 4800
- ClientLeft = 45
- ClientTop = 270
- ClientWidth = 6990
- LinkTopic = "Form1"
- ScaleHeight = 4800
- ScaleWidth = 6990
- StartUpPosition = 3 'Windows Default
- Begin VB.ListBox lstAttributes
- Height = 1860
- ItemData = "frmTest.frx":0000
- Left = 60
- List = "frmTest.frx":002B
- Sorted = -1 'True
- Style = 1 'Checkbox
- TabIndex = 8
- Top = 1188
- Width = 1668
- End
- Begin VB.CommandButton cmdExit
- Caption = "E&xit"
- Height = 336
- Left = 108
- TabIndex = 7
- Top = 4032
- Width = 1128
- End
- Begin VB.CheckBox chkRecurse
- Alignment = 1 'Right Justify
- Caption = "Recur&se"
- Height = 264
- Left = 108
- TabIndex = 4
- Top = 576
- Width = 984
- End
- Begin VB.CommandButton cmdEnum
- Caption = "Enumerate"
- Default = -1 'True
- Height = 336
- Left = 108
- TabIndex = 5
- Top = 3564
- Width = 1128
- End
- Begin VB.TextBox txtMask
- Height = 300
- Left = 936
- TabIndex = 3
- Text = "*.*"
- Top = 144
- Width = 768
- End
- Begin VB.TextBox txtRoot
- Height = 300
- Left = 2376
- TabIndex = 1
- Text = "c:\"
- Top = 144
- Width = 4476
- End
- Begin ComctlLib.ListView lvItems
- Height = 3648
- Left = 1872
- TabIndex = 6
- Top = 576
- Width = 4476
- _ExtentX = 7885
- _ExtentY = 6456
- View = 3
- LabelEdit = 1
- LabelWrap = -1 'True
- HideSelection = -1 'True
- _Version = 327682
- ForeColor = -2147483640
- BackColor = -2147483643
- BorderStyle = 1
- Appearance = 1
- NumItems = 0
- End
- Begin VB.Label Label3
- Caption = "Attributes:"
- Height = 228
- Left = 108
- TabIndex = 9
- Top = 936
- Width = 1308
- End
- Begin ComctlLib.ImageList imlSmallIcons
- Left = 1368
- Top = 4068
- _ExtentX = 794
- _ExtentY = 794
- BackColor = -2147483643
- MaskColor = 12632256
- _Version = 327682
- End
- Begin VB.Label Label2
- Caption = "File &Mask:"
- Height = 228
- Left = 108
- TabIndex = 2
- Top = 180
- Width = 804
- End
- Begin VB.Label Label1
- Caption = "&Root:"
- Height = 228
- Left = 1908
- TabIndex = 0
- Top = 180
- Width = 444
- End
- Attribute VB_Name = "frmTest"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Private Sub cmdEnum_Click()
- Dim oEnum As New SGFileSys.Enumerator
- ' Clear list view
- lvItems.ListItems.Clear
- Set lvItems.SmallIcons = Nothing
- imlSmallIcons.ListImages.Clear
- ' Set enumerator starting point and mask
- oEnum.NameMask = txtMask.Text
- oEnum.RootPath = txtRoot
- oEnum.Recurse = chkRecurse.Value
- oEnum.AttributeMask = GetSelectedAttributes
- Dim i&
- Dim viewItem As ListItem, smallIcon As StdPicture
- Dim fileItem As SGFileSys.Item
- i = 1
- ' Enumerate files
- On Error Resume Next
- For Each fileItem In oEnum.Items
- ' Limit to 500 files
- If (i > 500) Then Exit Sub
-
- ' Add item to the list view
- Set viewItem = lvItems.ListItems.Add(, , fileItem.Name)
- viewItem.SubItems(1) = fileItem.Drive & fileItem.Dir
- viewItem.SubItems(2) = fileItem.TypeName
-
- ' Add icon to the list view item
- 'Set smallIcon = fileItem.Icon(sgSmall_16x16)
- If Not smallIcon Is Nothing Then
- imlSmallIcons.ListImages.Add i, , smallIcon
- If i < 2 Then lvItems.SmallIcons = imlSmallIcons
- viewItem.smallIcon = i
- i = i + 1
- End If
- Next
- End Sub
- Private Sub cmdExit_Click()
- Unload Me
- End Sub
- Private Sub Form_Load()
- ' Initialize list view
- lvItems.ColumnHeaders.Add 1, , "File Name", 1600
- lvItems.ColumnHeaders.Add 2, , "File Path", 1600
- lvItems.ColumnHeaders.Add 3, , "Type", 1600
- imlSmallIcons.ListImages.Clear
- ' Default attribute mask is sgfAll
- lstAttributes.Selected(0) = True
- End Sub
- Private Sub Form_Resize()
- Dim nBorder&, nRight&
- If Me.Width < 4000 Or Me.Height < 4000 Then Exit Sub
- nBorder = 100
- ' Update item list position
- 'lvItems.Left = nBorder
- lvItems.Width = Me.ScaleWidth - lvItems.Left - nBorder
- lvItems.Height = Me.ScaleHeight - lvItems.Top - nBorder
- ' Update button positions
- nRight = lvItems.Left + lvItems.Width
- cmdExit.Top = Me.ScaleHeight - cmdExit.Height - nBorder
- cmdEnum.Top = cmdExit.Top - cmdEnum.Height - nBorder
- ' Edit boxes
- txtRoot.Width = nRight - txtRoot.Left
- End Sub
- Private Sub lvItems_DblClick()
- ' Open subdirectory
- If Not lvItems.SelectedItem Is Nothing Then
- If Right(txtRoot.Text, 1) <> "\" And _
- Right(txtRoot.Text, 1) <> "/" Then _
- txtRoot.Text = txtRoot.Text & "\"
- txtRoot.Text = txtRoot.Text & lvItems.SelectedItem.Text & "\"
- cmdEnum_Click
- End If
- End Sub
- Private Function GetSelectedAttributes()
- Dim i&
- GetSelectedAttributes = 0
- For i = 0 To lstAttributes.ListCount - 1
- If lstAttributes.Selected(i) Then
- Select Case lstAttributes.List(i)
- Case "sgfAll"
- GetSelectedAttributes = GetSelectedAttributes + sgfAll
- Case "sgfArchive"
- GetSelectedAttributes = GetSelectedAttributes + sgfArchive
- Case "sgfCompressed"
- GetSelectedAttributes = GetSelectedAttributes + sgfCompressed
- Case "sgfDirectory"
- GetSelectedAttributes = GetSelectedAttributes + sgfDirectory
- Case "sgfEncrypted"
- GetSelectedAttributes = GetSelectedAttributes + sgfEncrypted
- Case "sgfHidden"
- GetSelectedAttributes = GetSelectedAttributes + sgfHidden
- Case "sgfNormal"
- GetSelectedAttributes = GetSelectedAttributes + sgfNormal
- Case "sgfOffline"
- GetSelectedAttributes = GetSelectedAttributes + sgfOffline
- Case "sgfReadOnly"
- GetSelectedAttributes = GetSelectedAttributes + sgfReadOnly
- Case "sgfReparsePoint"
- GetSelectedAttributes = GetSelectedAttributes + sgfReparsePoint
- Case "sgfSparseFile"
- GetSelectedAttributes = GetSelectedAttributes + sgfSparseFile
- Case "sgfSystem"
- GetSelectedAttributes = GetSelectedAttributes + sgfSystem
- Case "sgfTemporary"
- GetSelectedAttributes = GetSelectedAttributes + sgfTemporary
- End Select
- End If
- Next
- End Function
-